package org.iipg.service.core.util;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.diboot.core.binding.Binder;
import org.iipg.common.data.dto.PageDto;

import java.util.List;

/**
 * @author zhuhy163@163.com
 * @Description
 * @date 2020/12/12 下午4:20
 */
public class ConvUtil {

    public static  <T, U> PageDto<T> convertAndBind(IPage<U> iPage, Class<T> T, Class<U> U) {
        List<T> voList = Binder.convertAndBindRelations(iPage.getRecords(), T);

        PageDto<T> voPageDto = new PageDto<>();
        voPageDto.setTotal(iPage.getTotal());
        voPageDto.setRecords(voList);
        return voPageDto;
    }

    public static  <T> List<T> convertAndBindList(List<?> list, Class<T> T) {
        List<T> voList = Binder.convertAndBindRelations(list, T);

        return voList;
    }

    public static <T, U> PageDto<T> convert(IPage<T> iPage, Class<T> T) {
        PageDto<T> pageDto = new PageDto<>();
        pageDto.setTotal(iPage.getTotal());
        pageDto.setRecords(iPage.getRecords());
        return pageDto;
    }

    public static <T, U> T convertObject(U source, Class<T> targetClass) {
        return Binder.convertAndBindRelations(source, targetClass);
    }
}
